package 滑动窗口;

public class 连续字符 {
    // 1.暴力解法
    public int maxPower(String s) {
        int max = 1;
        for (int i = 0; i < s.length(); i++) {
            for (int j = i+1; j < s.length(); j++) {
                if (s.charAt(i)==s.charAt(j)){
                    max = Math.max(max,j-i+1);
                }else
                    break;
            }
        }
        return max;
    }
    // 滑动窗口
    public int maxPower1(String s) {
        int max = 1;
        int left=0,right=1;
        while (right<s.length()){
            //如果相同
            if (s.charAt(right)==s.charAt(left)){
                right++;
                max = Math.max(max,right-left+1);
            }
            else{
                left = right;
                right+=1;
            }
        }
        return max;
    }
}
